package org.neurone.userspace.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.neurone.domain.Application;
import org.neurone.domain.UserInfo;
import org.neurone.domain.UserConfig;
import org.neurone.domain.persistence.UserConfigPersistence;
import org.neurone.domain.persistence.UserInfoPersistence;
import org.neurone.util.criteria.Criteria;

public class UserInfoDaoMock implements UserInfoDao {
	private HashMap<Long, UserInfo> userList;

	@Override
	public void deleteUser(Long userID) {
		userList.remove(userID);
	}

	@Override
	public UserInfo find(Long userID) {
		return userList.get(userID);
	}


	@Override
	public UserConfig getUserConfig(UserInfo userInfo) {
		return userInfo.getUserConfig();
	}

	@Override
	public Long newUser(UserInfo userInfo) {
		userList.put(userInfo.getUserID(), userInfo);
		return new Long(1);
	}

	@Override
	public List<UserInfo> search(Criteria terms, int pageSize, int pageIndex) {
		return new ArrayList<UserInfo>(userList.values());
	}

	@Override
	public void update(UserInfo userInfo) {
		userList.put(userInfo.getUserID(), userInfo);
	}

	@Override
	public void updateConfig(Long userID, UserConfig userConfig) {
		UserInfo userInfo = find(userID);
		((UserInfoPersistence)userInfo).setUserConfig(userConfig);
	}
	
	public UserInfoDaoMock(int recordCount)
	{
		userList = new HashMap<Long, UserInfo>();
		initUserData(recordCount);
	}
	
	public UserInfoDaoMock()
	{
		userList = new HashMap<Long, UserInfo>();
		initUserData(55);
	}
	
	private void initUserData(int recordCount)
	{		
		for (int i = 0; i < recordCount -1; i++) {
			UserConfigPersistence uc = new UserConfigPersistence();
			uc.setMessage2EmailNotify(true);
			uc.setUserConfigID(new Long(i));
			
			UserInfoPersistence ui = new UserInfoPersistence();
			ui.setEmail(i + "-email");
			ui.setImage(i + "-image");
			ui.setPasswd(i + "-passwd");
			ui.setRealName(i + "-realName");
			ui.setStatus("正常");
			ui.setUserConfig(uc);
			ui.setUserID(new Long(i));
			ui.setUserName(i + "-userName");
			ui.setUserNick(i + "-userNick");
			
			userList.put(new Long(i), ui);
		}
	}

	@Override
	public void assignApplication(Long userID, Long applicationID) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Application> listAssignedApplication(Long userID) {
		return new ArrayList<Application>();
	}

	@Override
	public void unassignApplication(Long userID, Long applicationID) {
		// TODO Auto-generated method stub
		
	}

}
